from PyQt5.Qt import *
from typing import *


class ETreeWidgetItem(QTreeWidgetItem):

    def __init__(self, *args, **kwargs):
        super(ETreeWidgetItem, self).__init__(*args, **kwargs)

    def setData(self, column: int, role: int, value: Any) -> None:
        # .isValid()

        ret1 = self.checkState(0) != value
        ret2 = (column == 0) and (role == Qt.CheckStateRole)  # 只判断第0列

        isCheckChange = ret1 and ret2
        super().setData(column, role, value)
        if isCheckChange:
            tree = self.treeWidget()
            tree.itemCheckStateChanged.emit(self, self.checkState(0) == Qt.Checked)


class ETreeWidget(QTreeWidget):

    itemCheckStateChanged = pyqtSignal(ETreeWidgetItem, bool)
    def __init__(self, *args, **kwargs):
        super(ETreeWidget, self).__init__(*args, **kwargs)




